package getproperties.ByProperties;

import org.springframework.stereotype.Controller;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @Description
 * @Author zhoucq
 * @Date 2025/9/27 16:13
 * @Version 1.0
 * 通过ClassLoader或InputStream加载.properties文件，利用Properties.load()方法读取键值对。
 */
@Controller
public class Demo01 {
    public static void main(String[] args) {
        //支持从类路径或绝对路径加载文件，适用于简单配置场景
        Properties prop = new Properties();
        try (InputStream input = Demo01.class.getClassLoader().getResourceAsStream("config/config01.properties")) {
            prop.load(input);
            String value = prop.getProperty("properties.demo01.name");
            System.out.println(value);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
